<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      function sum(value = 0) {
        if (sum.r === undefined) sum.r = 0;
        sum.r += value;
        sum.toString = function () {
          return this.r;
        };
        return sum;
      }
      console.log(+sum(1)(2)(3));
      console.log(sum(1)(2) + 200 + sum(3)(4));
      console.log(sum(1)(2) + +sum(3)(4));
      // console.log(sum(1)(2) + 100);
    </script>
  </body>
</html>
